package com.xinchengxd.email.receiver;

import com.xinchengxd.commons.entity.dto.MailDTO;
import com.xinchengxd.email.service.EmailService;
import com.xinchengxd.email.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author: 姚新成
 * @Date: 2021/11/25:20:20
 * @Description: 监听死信队列，取回数据，判断是否支付。
 */

@Slf4j
@Component
@RabbitListener(queues = "yxc_payout_queue")   //指定监听哪些队列
public class PayReceiver {
    @Autowired
    private EmailService emailService;
    @Autowired
    private OrderService orderService;

    @RabbitHandler   //处理消息的方法
    public void receive(MailDTO email) {
        log.debug("接收的信息：{}", email);
        String orderNo = email.getOrderNo();
        Boolean isPay = orderService.isPay(orderNo);
        log.debug("isPay:{}",isPay);
        if(!isPay){
            /*发送数据*/
            emailService.emailSend(email,2);
        }
    }

    @RabbitHandler   //处理消息的方法
    public void receive(String us) {

        log.debug("string us:{}",us);
    }

}
